package com.apes.fn.business.insurance.modle;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.*;

/**
 * @ClassName CommissionReconciliationItem
 * @Author wsj
 * @Date 2021/6/16 17:13
 * @description 佣金对账明细
 */

@Entity
@EntityListeners(DefaultPersistListener.class)
@Getter
@Setter
@Table(name = CommissionReconciliationItem.CONST_TABLE_NAME)
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
public class CommissionReconciliationItem extends BaseModel {
    public final static String CONST_TABLE_NAME = "commission_reconciliation_item";

    @Id
    @Column(name = "id", nullable = false,length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "佣金对帐明细")
    @Comment("明细序列")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("门店")
    private Dept dept;

    @ManyToOne(optional = false)
    @JoinColumn(name = "commission_Reconciliation",referencedColumnName = "id",nullable = false)
    private CommissionReconciliation commissionReconciliation;

    @Column(name = "policy_Number",length = 64)
    @Comment("保单号")
    private String policyNumber;

    @Column(name = "remark",length = 248)
    @Comment("备注")
    private String remark;

    @Column(name = "car_License",length = 64)
    @Comment("车牌")
    private String carLicense;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "start_Date")
    @Comment("起保时间")
    private Date startDate;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "end_Date")
    @Comment("终保时间")
    private Date endDate;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "issue_Order_Date")
    @Comment("出单时间")
    private Date issueOrderDate;

    @Column(name = "car_Ownership",length = 64)
    @Comment("车辆所有权(1:个人，2:单位)")
    private String carOwnership;

    @Column(name = "insurance_Type", length = 32)
    @Comment("险种类别(0:商业险,1：交强险,2:驾意险)")
    private String insuranceType;

    @Column(name = "commission_Type",length = 64)
    @Comment("佣金类型")
    private String commissionType;

    @Comment("保险金额")
    @Column(name = "insurance_amount",nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private Double insuranceAmount;

    @Comment("净保费")
    @Column(name = "net_Premium",nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private Double netPremium;

    @Comment("佣金比率")
    @Column(name = "commission_Ratio",nullable = false, columnDefinition = ApesConst.FIELD_ROUND_16_8)
    private double commissionRatio = 0;

    @Comment("佣金金额")
    @Column(name = "commission",nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double commission = 0 ;

    @Comment("保险公司佣金")
    @Column(name = "insurance_Commission", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double insuranceCommission = 0;

    @Comment("调整金额")
    @Column(name = "adjustment_Amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double adjustmentAmount = 0;

    @Comment("差价")
    @Column(name = "difference_Price", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double differencePrice = 0;

    @Comment("已开票金额")
    @Column(name = "blend_Amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double invoicedAmount = 0;

    @Transient
    private boolean selected;

    @Comment("未开票金额")
    @Column(name = "un_Invoiced_Amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double unInvoicedAmount = 0;

    @Column(name = "transfer_ownership", length = 32)
    @Comment("是否过户车")
    private String transferOwnership;

    @Column(name = "check_and_ratify ", length = 32)
    @Comment("是否过户车（1：是，0：否）")
    private String checkAndRatify;

    @Column(name = "energy", length = 32)
    @Comment("能源类型(0：燃油，1：纯电动，2：燃料电池，3：插电式混合动力，4：其他混合动力)")
    private String energy;

    @Column(name = "grade", length = 32)
    @Comment("保险公司评分")
    private String grade;

    @Column(name = "renew_insurance", length = 32)
    @Comment("是否续保（1：是，0：否）")
    private String renewInsurance;

    @Column(name = "city", length = 32)
    @Comment("城市名称")
    private String city;

    @Column(name = "province", length = 32)
    @Comment("省份")
    private String province;

    @Transient
    public static  final Map<String,Object > FIELD_COMMENTARY = new HashMap<String, Object>() {
        {
            put("carOwnership",
                    new Object() {
                        {   put("1","个人");
                            put("2","单位");
                        }
                    });
            put("insuranceType", new Object() {
                {   put("0","商业险");
                    put("1","交强险");
                    put("2","驾意险");
                }
            });
        }
    };

    @Transient
    private Map insuranceTypeTemp;
    public Map getInsuranceTypeTemp(){
        if (insuranceType == null) return null;
        Map map = new HashMap<>();
        switch (insuranceType){
            case "商业险":map.put("id","0");map.put("name","商业险");break;
            case "交强险":map.put("id","1");map.put("name","交强险");break;
            case "驾意险":map.put("id","2");map.put("name","驾意险");break;
        }
        return map;
    }

    @Transient
    private Dept deptTemp;
    public Dept getDeptTemp(){
        return dept;
    }

}
